<!--
  * 地址搜索推荐地址
-->
<template>
  <a-form class="smart-query-form">
    <a-row class="smart-query-form-row">
      <a-form-item label="用户地址" class="smart-query-form-itme" name="certAddress">
        <a-input style="width: 500px" v-model:value="queryForm.certAddress" placeholder="请输入地址" />
      </a-form-item>
      <a-form-item label="楼盘名称" class="smart-query-form-itme" name="communityName">
        <a-input style="width: 500px" v-model:value="queryForm.communityName" placeholder="请输入楼盘名称" />
      </a-form-item>
      <a-form-item label="城市" class="smart-query-form-itme smart-margin-left10" name="cityCode">
        <DictSelectType ref="dictSelectType" :service-id="SERVICE_ID_ENUM.DICTIONARY.value" :dcit-type="DICT_TYPE_ENUM.CITY_SELECT.value" :width="'120px'"  :height="400" v-model:value="queryForm.cityCode" />
      </a-form-item>
      <a-form-item class="smart-query-form-item smart-margin-left10">
        <a-button type="primary" @click="ajaxQuery">
          <template #icon>
            <SearchOutlined />
          </template>
          查询
        </a-button>
        <a-button @click="resetQuery">
          <template #icon>
            <ReloadOutlined />
          </template>
          重置
        </a-button>
      </a-form-item>
    </a-row>
  </a-form>

  <a-card size="small" :bordered="false" :hoverable="true">
    <a-table
      :scroll="{ x: 1300 }"
      size="small"
      :dataSource="tableData"
      :columns="columns"
      rowKey="house_code"
      :pagination="false"
      :loading="tableLoading"
      bordered
    >
    </a-table>
  </a-card>
</template>
<script setup lang="ts">
  import { reactive, ref, onMounted,computed } from 'vue';
  import { asApi } from '/@/api/addrstandard/as-api'
  import { smartSentry } from '/@/lib/smart-sentry';
  import DictSelectType from '/@/components/cache/dict-select-type.vue'
  import { SERVICE_ID_ENUM,DICT_TYPE_ENUM } from '/@/constants/system/cache-service-id-const';
  import { message } from 'ant-design-vue';

  // --------------------------- 企业表格 列 ---------------------------

  const columns = ref([
  {
      title: '用户地址',
      dataIndex: 'userCertAddress',
      // width: 150,
    },
    {
      title: '房屋编码',
      dataIndex: 'houseCode',
      width: 120,
    },
    {
      title: '字典地址',
      dataIndex: 'dictCertAddress',
      // width: 150,
    },
    {
      title: '楼盘',
      dataIndex: 'communityName',
      width: 120,
      ellipsis: true,
    },
    {
      title: '楼栋全称',
      dataIndex: 'buildingName',
      width: 120,
      ellipsis: true,
    },
    {
      title: '门牌号',
      dataIndex: 'buildingAddr',
      width: 120,
      ellipsis: true,
    },
    {
      title: '楼栋号',
      dataIndex: 'buildingNum',
      width: 120,
      ellipsis: true,
    },
    {
      title: '单元号',
      dataIndex: 'unitNum',
      width: 80,
      ellipsis: true,
    },
    {
      title: '房号',
      dataIndex: 'houseNumber',
      width: 80,
      ellipsis: true,
    },
    {
      title: '匹配类型',
      dataIndex: 'matchName',
      width: 80,
    },
    {
      title: '省',
      dataIndex: 'provinceName',
      width: 80,
    },
    {
      title: '市',
      dataIndex: 'cityName',
      width: 80,
      ellipsis: true,
    },
    {
      title: '区/县',
      dataIndex: 'districtName',
      width: 80,
      ellipsis: true,
    },
  ]);

  // --------------------------- 查询 ---------------------------

  const queryFormState = {
    certAddress: undefined,
    cityCode: undefined,
    communityName: undefined,
  };
  const queryForm = reactive({ ...queryFormState });
  const tableLoading = ref(false);
  const tableData = ref([]);

  function resetQuery() {
    Object.assign(queryForm, queryFormState);
    ajaxQuery();
  }

  async function ajaxQuery() {
    try {
      if(!queryForm.certAddress || !queryForm.cityCode)
        message.error("城市及地址信息不能为空！")
      else{
        tableLoading.value = true;
        let responseModel = await asApi.searchAddress(queryForm.certAddress,queryForm.communityName,queryForm.cityCode);
        tableData.value = responseModel.data;
      }
    } catch (e) {
      smartSentry.captureError(e);
    } finally {
      tableLoading.value = false;
    }
  }
</script>
